<?php

require_once('persistence/GenericTopicDao.class.php');
require_once('persistence/GenericVoteDao.class.php');
require_once('persistence/GenericCategoryDao.class.php');
require_once('persistence/GenericUserDao.class.php');

abstract class AbstractRequest {
	
	/**
	 * TopicsDAO
	 *
	 * @var ITopicDao
	 */
	protected $topicDao;
	
	/**
	 * VoteDAO
	 *
	 * @var IVoteDao
	 */
	protected $voteDao;
	
	/**
	 * CategoryDAO
	 *
	 * @var ICategoryDao
	 */
	protected $categoryDao;
	
	/**
	 * UserDAO
	 *
	 * @var IUserDao
	 */
	protected $userDao;
	
	public function AbstractRequest($db) {
		if(!$db) {
			throw new Exception("Invalid DB handle!");
		}
		
		$this->topicDao = new GenericTopicDao($db);
		$this->voteDao = new GenericVoteDao($db);
		$this->categoryDao = new GenericCategoryDao($db);
		$this->userDao = new GenericUserDao($db);
	}
	
	public function execute() {
		Log::instance()->info("Executing request [" . get_class($this) . "].");
		$requestXml = null;
		if(isset($_POST['xml_data'])) {
			Log::instance()->debug("Sent POST xml_data is [" . $_POST['xml_data'] . "].");
			$requestXml = simplexml_load_string($_POST['xml_data']);
		}
		
		$this->internalExecute($requestXml);
	}
	
	protected abstract function internalExecute($requestXml);
	
}

?>